<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: PHP@妖孽 <dino_ma@163.com>
// +----------------------------------------------------------------------------
namespace Home\Controller;
use Home\Controller;
class IndexController extends HomeController {
    
	public function index(){
	    //促销列表
    	$obj = D('Admin/ServiceApi');
	    $where_promotion = array(
	        'goods_type' => 1,
	        'status'   => 1,
	        'position' => 1,
	    );
	    $promotion_ids = array();
	    $field = 'goods_id,goods_name,pic_id';
	    $promotion_list = $obj->getSaleGoodsNum($where_promotion, $field, 3);
	    if($promotion_list){
	        $promotion_ids = array_column($promotion_list, 'goods_id');
	    }
	    //促销列表数据组合
	    $goods_promotion = ($promotion_ids)? $obj->getSaleGoodsPromotion($promotion_ids) : array();
	    if($promotion_ids){
	        //促销数据添加
	        foreach ($promotion_list as $key=>$val){
	            $promotion_type = (!empty($goods_promotion[$val['goods_id']]))? true : false ;
// 	            $promotion_list[$key]['promotion_pic_id'] = ($promotion_type)? $goods_promotion[$val['goods_id']]['promotion_pic_id'] : '' ;
// 	            $promotion_list[$key]['promotion_stock'] = ($promotion_type)? $goods_promotion[$val['goods_id']]['promotion_stock'] : '' ;
	            $promotion_list[$key]['promotion_price'] = ($promotion_type)? $goods_promotion[$val['goods_id']]['promotion_price'] : '' ;
// 	            $promotion_list[$key]['promotion_start_time'] = ($promotion_type)? $goods_promotion[$val['goods_id']]['promotion_start_time'] : '' ;
// 	            $promotion_list[$key]['promotion_end_time'] = ($promotion_type)? $goods_promotion[$val['goods_id']]['promotion_end_time'] : '' ;
	        }
	    }
	    $this->meta_title = '哈尔滨家家户户网_装修_建材团购_家具团购_家装一站式采购平台';
	    $this->assign('_list', $promotion_list);
	    if(isMobile()){
	        $this->display('index_m');
	    }else{
	        $this->display('index');
	    }
	}
	
// 	public function loginOut(){
// 	   if(is_login()){
//             D('Customer')->autoLoginOut();
//             session('[destroy]');
//             $this->success('退出成功！', U('login'));
//         } else {
//             $this->redirect('login');
//         }
// 	}

	
	//demo replace into
// 	//之后根据偏移量查询
// 	public function test(){
	  
// 	    //取最大的id,然后去大于这个id的数据,然后写入
// 	    //如果最大的为0则全部拉去
//         $service_activity_obj = M('ServiceActivity');
//         $activity_id = $service_activity_obj->max('`activity_id`');
//         if(is_null($activity_id)){
//             //数据表为空拉全部
//         }else{
//             //取偏移量大于
//             //如果取回的数量大于0则写入
//         }
// 	    $activity_obj = M('activity');
//         $activity_list= $activity_obj->field('activity_id,activity_name,start_time,end_time')->select();
//         $service_activity_obj->addAll($activity_list,array(),true);
// 	}

}
